function [c_idat l_idat] = fsb_lens_brain(c_idat,threshold,cent2)

% FSB : creates a lens shaped filter and applies it to a volume 
%
% EXAMPLE:
% [c_idat l_idat] = fsb_lens_brain(c_idat,30,24,24,24)
%
% INPUT
% c_idat: 3D-Image data
% threshold:    filter threshold
% cent2: Center of filter
%
% OUTPUT:
% l_idat: lens-filter processed mean image
% c_idat: lens filter created
% 
% CALLED BY:
% FSB.m
%
% NOTES
% Used to improve brain extraction in fMRI Sandbox
% Threshold is at around 3. Purpose of the filter is to get clearer distinction between
% brain and muscle in the monkey brain.
% In this revised version, the center of the filter depends on the position
% of the crosshair in sandbox instead of the image center, giving the user
% the possibility to selectively enhance parts of the image (e.g. the PFC)
%
% Copyright 2010 MPI for Biological Cybernetics
% Author: Steffen Stoewer
% License:GNU GPL, no express or implied warranties
% 
% $ Revision 1.0
%
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Determine size of c_idat
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dim = size(c_idat);

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% create an array of ones and apply a gaussian filter
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
f_idat = single(ones (dim(1),dim(2),dim(3)));
px = single(pdf('Normal',1:dim(1),cent2(1),dim(1)/threshold-6));
py = single(pdf('Normal',1:dim(2),cent2(2),dim(2)/threshold));
px = px/max(px);
py = py/max(py);

for nx = 1:dim(1);
    f_idat(nx,:,:) =f_idat(nx,:,:).*px(nx);
end
        
for ny = 1:dim(2);
    f_idat(:,ny,:) =f_idat(:,ny,:).*py(ny);
end

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Multiply with original idat
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
l_idat =single(c_idat).*f_idat;
c_idat = single(f_idat);


end
